//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#ifndef __CBASICFILE_H__
#define __CBASICFILE_H__

#define MIN_TIME_VALUE  315532800 //from 1970.1.1 to 1980.1.1
const wchar_t wszIllegal[] = L"\"*\\<>/?:|";

class CBasicFile : public IBasicFile, IAbsoluteIO, IFileMonitor
{
public:
    CARAPI_(PInterface) Probe(
         /* [in]  */ REIID riid);

    CARAPI_(UInt32) AddRef(void);

    CARAPI_(UInt32) Release(void);

    CARAPI Aggregate(
        /* [in] */ AggrType aggrType,
        /* [in] */ PInterface pObject);

    CARAPI GetDomain(
         /* [out] */ PInterface *ppObj);

    CARAPI Read(
        /* [in] */ Int32 offset,
        /* [in] */ Int32 toRead,
        /* [out] */ MemoryBuf * pBuf);

    CARAPI Write(
        /* [in] */ Int32 offset,
        /* [in] */ const MemoryBuf & ezbBuf,
        /* [out] */ Int32 * pWrite);

    CARAPI GetSize(
        /* [out] */ Int32 * pSize);

    CARAPI SetSize(
        /* [in] */ Int32 size);

    CARAPI GetOptimalBlockSize(
        /* [out] */ Int32 * pSize);

    CARAPI Sync();

    CARAPI GetType(
        /* [out] */ FileType * pType);

    CARAPI GetAccessTime(
        /* [out] */ Int32 * pTime);

    CARAPI SetAccessTime(
        /* [in] */ Int32 time);

    CARAPI GetModificationTime(
        /* [out] */ Int32 * pTime);

    CARAPI SetModificationTime(
        /* [in] */ Int32 time);

    CARAPI GetCreateTime(
        /* [out] */ Int32 * pTime);

    CARAPI CheckAccessMode(
        /* [in] */ FileAccessMode mode);

    CARAPI GetAccessMode(
        /* [out] */ FileAccessMode * pMode);

    CARAPI SetAccessMode(
        /* [in] */ FileAccessMode mode);

    CARAPI GetShareMode(
        /* [out] */ FileShareMode *pMode);

    CARAPI SetShareMode(
        /* [in] */ FileShareMode mode);

    CARAPI AddFileMonitor(
        /* [out] */ IEvent **pEvent);

    CARAPI RemoveFileMonitor(
        /* [in] */ IEvent *pEvent);

    CBasicFile();
    CBasicFile(WString esFileName, BOOL bIsExist, BOOL bIsWritable);
    virtual ~CBasicFile();

private:
    // TODO: Add you private member variables here
    Interlocked     m_cRef;

    wchar_t* m_wstrFileName;
    FileAccessMode m_eFMode;
    Int32 m_iCreateTime;
    Int32 m_iAccessTime;
    Int32 m_iModificationTime;

    HANDLE  m_FileHandle;
    HANDLE  m_FileLock;
};

#endif // __CBASICFILE_H__
